package raft;

import com.sun.org.apache.xerces.internal.impl.xs.opti.DefaultNode;
import raft.node.NodeConfig;
import raft.service.impl.NodeImpl;

import java.util.Arrays;

public class RaftNodeBootStrap {

    public static void main(String[] args) {
        star(8775);
    }
//, "localhost:8778", "localhost:8779"
    public static void star(int port) {
        String[] peerAddr = {"localhost:8775","localhost:8776","localhost:8777"};

        NodeConfig config = new NodeConfig();

        // 自身节点  Integer.valueOf(System.getProperty("serverPort"))
        config.setSelfPort(port);

        // 其他节点地址
        config.setPeerAddrs(Arrays.asList(peerAddr));

        NodeImpl node = NodeImpl.getInstance();
        node.setConfig(config);

        node.init();

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            try {
                node.destroy();
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        }));

    }


}
